package unit6.IntroduceExplainingVariable;

/**
 * 引入解释性变量
 * （考虑使用场景）
 */
public class Example1 {

    String platform;
    String browser;
    int resize;

    private boolean wasInitialized() {
        return false;
    }

    /**
     * 例1
     * before refactoring
     */
    public void test1() {
        if (platform.toUpperCase().indexOf("MAC") > -1
                && browser.toUpperCase().indexOf("IE") > -1
                && wasInitialized()
                && resize > 0) {
            // do something
        }
    }

    /**
     * after refactoring
     */
    final boolean isMacOs = platform.toUpperCase().indexOf("MAC") > -1;
    final boolean isIEBrowser = browser.toUpperCase().indexOf("MAC") > -1;
    final boolean wasResized = resize > 0;

    public void test1a() {
        if (isMacOs && isIEBrowser && wasInitialized() && wasResized) {
            // do something
        }
    }


}
